package com.itheima.a01jdk7datedemo;

import java.util.Calendar;
import java.util.Date;

public class CalendarDemo1 {
    public static void main(String[] args) {
        //获取日历对象
        Calendar c1 = Calendar.getInstance();

        //获取日期对象
        Date d = c1.getTime();
        System.out.println(d);
        //给日历设置日期对象
        c1.setTime(d);
        //System.out.println(c);
        //拿到时间毫秒值
        c1.getTimeInMillis();
        System.out.println(c1.getTimeInMillis());
        //给日历设置时间毫秒值
        c1.setTimeInMillis(0L);
        System.out.println(c1.getTimeInMillis());

        //取日期中某个字段信息
        Calendar c2 = Calendar.getInstance();
        Date d2 = c2.getTime();
        int i = c2.get(Calendar.YEAR);
        System.out.println(i);
        //修改某个字段信息
        c2.set(Calendar.YEAR, i+1);
        System.out.println(c2.get(Calendar.YEAR));
        //为某个字段增加减少指定的值
        c2.add(Calendar.YEAR, -1);
        System.out.println(c2.get(Calendar.YEAR));

        c2.get(Calendar.MONTH);
        System.out.println(c2.get(Calendar.MONTH)+1+"月"+getDay(c2.get(Calendar.DAY_OF_WEEK)) );


    }
    public static String getDay(int day) {
        String[] str={"","星期天","1","2","3","4","5","6"};
        return str[day];
    }
}
